package game.dungeon;

import static org.junit.Assert.assertTrue;
import game.border.Border;
import game.border.Wall;
import game.square.Direction;
import game.square.Rock;
import game.square.Square;
import game.square.SquareInterface;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class DungeonTest {

	private static Dungeon<Square> dungeon;
	
	@Before
	public void setUp() throws Exception {
		dungeon = new Level<Square>(10,10,0);
		
	}
	
	@Test
	public final void testGetAllSpaces() {
		Square square1 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square2 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square3 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square4 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square5 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square6 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square7 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square8 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square9 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square10 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square11 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square12 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square13 = new Rock();
		
		Coordinates coordinates1 = new Coordinates(1,1,0);
		Coordinates coordinates2 = new Coordinates(2,1,0);
		Coordinates coordinates3 = new Coordinates(3,1,0);
		Coordinates coordinates4 = new Coordinates(4,1,0);
		Coordinates coordinates5 = new Coordinates(1,2,0);
		Coordinates coordinates6 = new Coordinates(1,3,0);
		Coordinates coordinates7 = new Coordinates(1,4,0);
		Coordinates coordinates8 = new Coordinates(2,3,0);
		Coordinates coordinates9 = new Coordinates(2,4,0);
		
		Coordinates coordinates10 = new Coordinates(4,3,0);
		Coordinates coordinates11 = new Coordinates(4,4,0);
		Coordinates coordinates12 = new Coordinates(5,4,0);
		Coordinates coordinates13 = new Coordinates(5,3,0);
		
		dungeon.addSquare(square1, coordinates1);
		dungeon.addSquare(square2, coordinates2);
		dungeon.addSquare(square3, coordinates3);
		dungeon.addSquare(square4, coordinates4);
		dungeon.addSquare(square5, coordinates5);
		dungeon.addSquare(square6, coordinates6);
		dungeon.addSquare(square7, coordinates7);
		dungeon.addSquare(square8, coordinates8);
		dungeon.addSquare(square9, coordinates9);
		
		dungeon.addSquare(square10, coordinates10);
		dungeon.addSquare(square11, coordinates11);
		dungeon.addSquare(square12, coordinates12);
		
		dungeon.addSquare(square13, coordinates13);
		
		List<List<Square>> spaces = dungeon.getSpaces();
//		System.out.println("debug : Size of list of spaces : " + spaces.size());
//		for(List<Square> space : spaces) {
//			System.out.println("debug : Size space : " + space.size());	
//		}
		assertTrue(spaces.size() == 3);
	}

	@Test
	public final void testWeightedSum() {
		double valueOne = 30;
		double valueTwo = 0;
		double weightOne = 2;
		double weightTwo = 4;
		double returnValue = dungeon.weightedSum(valueOne, weightOne, valueTwo, weightTwo);
		double expectedValue = 10;
//		System.out.println("expected = " + expectedValue + "   <>   returned = " + returnValue);
		assertTrue(Double.compare(expectedValue, returnValue) == 0);
	}
	
	@Test
	public final void testGetRandomSquare() {
		Square square1 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square2 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square3 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square4 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square5 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square6 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square7 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square8 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square9 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square10 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square11 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square12 = new Square(new Border(Direction.FLOOR,new Wall()));
		Square square13 = new Rock();
		Coordinates coordinates1 = new Coordinates(1,1,0);
		Coordinates coordinates2 = new Coordinates(2,1,0);
		Coordinates coordinates3 = new Coordinates(3,1,0);
		Coordinates coordinates4 = new Coordinates(4,1,0);
		Coordinates coordinates5 = new Coordinates(1,2,0);
		Coordinates coordinates6 = new Coordinates(1,3,0);
		Coordinates coordinates7 = new Coordinates(1,4,0);
		Coordinates coordinates8 = new Coordinates(2,3,0);
		Coordinates coordinates9 = new Coordinates(2,4,0);
		Coordinates coordinates10 = new Coordinates(4,3,0);
		Coordinates coordinates11 = new Coordinates(4,4,0);
		Coordinates coordinates12 = new Coordinates(5,4,0);
		Coordinates coordinates13 = new Coordinates(5,3,0);
		dungeon.addSquare(square1, coordinates1);
		dungeon.addSquare(square2, coordinates2);
		dungeon.addSquare(square3, coordinates3);
		dungeon.addSquare(square4, coordinates4);
		dungeon.addSquare(square5, coordinates5);
		dungeon.addSquare(square6, coordinates6);
		dungeon.addSquare(square7, coordinates7);
		dungeon.addSquare(square8, coordinates8);
		dungeon.addSquare(square9, coordinates9);
		dungeon.addSquare(square10, coordinates10);
		dungeon.addSquare(square11, coordinates11);
		dungeon.addSquare(square12, coordinates12);
		dungeon.addSquare(square13, coordinates13);

		int counter = 0;
		while(counter < 20){
			SquareInterface s = dungeon.getRandomSquare();
			if(s == null)
				throw new IllegalStateException();
			counter++;
		}
	}

}
